#include "atoms.h"

//************************************
//*************Creacion***************
//************************************

void crearAtoms(Atoms &atoms){
    atoms = NULL;
};

void insertaAtoms(Atoms &atoms, char letra){
    Atoms aux, copia = atoms;
    aux = new NodoAtoms;
    aux->atom = letra;
    aux->sig = NULL;

    if(copia==NULL)
        atoms=aux;
    else{
        while(copia->sig != NULL)
            copia = copia->sig;
        copia->sig = aux;
    }
}

//************************************
//***********Eliminacion**************
//************************************
void borrarAtoms(Atoms &atoms){

    while(atoms!=NULL){
        Atoms aux;
        aux=atoms->sig;
        delete atoms;
        atoms=aux;
    }

}

//************************************
//************Existencia**************
//************************************
void desplegarAtoms(Atoms atoms){
    if (atoms!= NULL){
        printf("%c ",atoms->atom);
        desplegarAtoms(atoms->sig);
    }
}

//************************************
//************Despliegue**************
//************************************
bool existeAtom(Atoms atoms,char letraProp){
bool existe=false;
    while (atoms!= NULL&&!existe){
        if(atoms->atom==letraProp)
            existe=true;
        else
            atoms=atoms->sig;
    }
    return existe;
}

//************************************
//************Consultas***************
//************************************
int cuentaAtoms(Atoms atoms){
int cantidadAtoms=0;
    while (atoms!=NULL){
        cantidadAtoms++;
        atoms=atoms->sig;
    }
    return cantidadAtoms;
}


int posicionDelAtomo(Atoms atoms,char letraProp){
int posicionAtomo=0;
bool encontreAtomo=false;

    while (atoms!=NULL&&!encontreAtomo){
        if(atoms->atom==letraProp)
            encontreAtomo=true;
        else{
            posicionAtomo++;
            atoms=atoms->sig;
        }
    }
    return posicionAtomo;
}


int potenciaAtoms(int cantAtoms){

    if(cantAtoms==0)
        return 1;
    else
        return 2 * potenciaAtoms(cantAtoms-1);

}






